import './roleNew.scss'
import '../../static/font/iconfont.css'
import http from '../../utils/http'
import { Form, Input, Button, Select, Modal, DatePicker } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import store from '../../store';
const { Option } = Select;
const { confirm } = Modal;
const layout = {
    labelCol: {
        span: 6,
    },
    wrapperCol: {
        span: 14,
    },
};
const tailLayout = {
    wrapperCol: {
        offset: 10,
        span: 16,
    },
};
const RoleManNew = ({ setState }) => {
    const [form] = Form.useForm();
    form.setFieldsValue({
        adId:store.wuxiaoyuan.operator
     })
    //返回页面
    const backCar = () => {
        setState(1)
    }
    const quxiao = () => {
        confirm({
            icon: <ExclamationCircleOutlined />,
            content: '您确定离开此页面吗？',
            cancelText: '取消',
            okText: '确定',
            onOk() {
                //   console.log('OK');
                backCar()
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }
    const onFinish = (values) => {
        let createtime;
        if (values.roCreatetime) {
            let date = new Date(values.roCreatetime)
            let y = date.getFullYear()  //获取年份
            let m = date.getMonth() + 1  //获取月份
            m = m < 10 ? "0" + m : m  //月份不满10天显示前加0
            let d = date.getDate()  //获取日期
            d = d < 10 ? "0" + d : d  //日期不满10天显示前加0
            createtime = y + "-" + m + "-" + d;
        }
        values.roCreatetime = createtime
        console.log(values);
        http({
            url:'/roleinfo/addRoleInfo',
            method:'post',
            data:values
        }).then((res)=>{
            console.log(res)
        form.resetFields();
        })
    };

    return <div className="xinzeng">
        <div>
            <div className='tit'>
                <div>
                    <div>
                        <div></div>
                        <div>角色信息新增</div>
                    </div>
                </div>
                <div>
                    <span className="iconfont icon-a-16guanbi" onClick={backCar}></span>
                </div>
            </div>
            <hr></hr>
            <div className='content'>
                <div>
                    <div>
                        <div>
                            <Form {...layout} form={form} name="control-hooks" onFinish={onFinish}>
                                <Form.Item
                                    name="roName"
                                    label="角色名称"
                                    rules={[
                                        {
                                            required: true,
                                        },
                                    ]}
                                >
                                    <Input />
                                </Form.Item>
                                <Form.Item
                                    name="roType"
                                    label="角色类型"
                                    rules={[
                                        {
                                            required: true,
                                        },
                                    ]}
                                >
                                    <Select
                                        placeholder="请选择创建状态"
                                        allowClear
                                    >
                                        <Option value="1">普通角色</Option>
                                        <Option value="0">系统角色</Option>
                                    </Select>
                                </Form.Item>
                                <Form.Item
                                    name="roState"
                                    label="启用状态"
                                    rules={[
                                        {
                                            required: true,
                                        },
                                    ]}
                                >
                                    <Select
                                        placeholder="请选择状态"
                                        allowClear
                                    >
                                        <Option value="0">启用</Option>
                                        <Option value="1">禁用</Option>
                                    </Select>
                                </Form.Item>
                                <Form.Item
                                    name="roCreatetime"
                                    label="创建时间"
                                    rules={[
                                        {
                                            required: true,
                                        },
                                    ]}
                                >
                                    <DatePicker style={{ width: '100%' }} />
                                </Form.Item>
                                <Form.Item
                                    name="adId"
                                    label="操作人"
                                    rules={[
                                        {
                                            required: true,
                                        },
                                    ]}
                                >
                                    <Input disabled/>
                                </Form.Item>
                                <Form.Item {...tailLayout}>
                                    <Button type="primary" htmlType="submit">
                                        提交
                                    </Button>
                                    <Button htmlType="button" onClick={quxiao} style={{ marginLeft: '20px' }}>
                                        取消
                                    </Button>
                                </Form.Item>
                            </Form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

}
export default RoleManNew